package cn.wolfcode.luowowo.article.service.impl;

import cn.wolfcode.luowowo.article.domain.StrategyCommend;
import cn.wolfcode.luowowo.article.mapper.StrategyCommendMapper;
import cn.wolfcode.luowowo.article.query.StrategyCommendQuery;
import cn.wolfcode.luowowo.article.service.IStrategyCommendService;
import com.alibaba.dubbo.config.annotation.Reference;
import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.List;

@Service
public class StrategyCommendServiceImpl implements IStrategyCommendService {

    @Autowired
    private StrategyCommendMapper commendMapper;

    @Override
    public PageInfo query(StrategyCommendQuery qo) {
        PageHelper.startPage(qo.getCurrentPage(), qo.getPageSize());
        List<StrategyCommend> list = commendMapper.selectAll();
        return new PageInfo(list);
    }

    @Override
    public void saveOrUpdate(StrategyCommend strategyCommend) {
        if(strategyCommend.getId()==null){
            commendMapper.insert(strategyCommend);
        }else {
            commendMapper.updateByPrimaryKey(strategyCommend);
        }
    }

    @Override
    public void delete(Long id) {
        commendMapper.deleteByPrimaryKey(id);
    }

    @Override
    public List<StrategyCommend> getTop5() {
        List<StrategyCommend> list = new ArrayList<>();
        list = commendMapper.getTop5();
        return list;
    }

}
